home *** CD-ROM | disk | FTP | other *** search
- COMPANION DISK TO VARIATIONS IN C
-
-
- This Companion Disk is for use in conjunction with the book
- "Variations in C", by Steve Schustack (Microsoft Press, 1985), to help
- you learn to program in the C language. To use the disk, you will need
- MS-DOS, version 2.0 or higher, and the Microsoft C Compiler, version
- 3.0 or higher.
-
- ***Before you read any further, take a minute to make a backup copy of
- the disk, and store the original in a safe place.***
-
- CONTENTS OF THE DISK:
- The Companion Disk contains all of the functions and header files that
- appear in "Variations in C", as well as selected illustrative code
- segments. All C code is in uncompiled source form, stored in separate
- ASCII text files, ready for you to edit and compile.
- There are four kinds of C code on the disk: an application, individual
- functions, header files, and code segments. Before we look at ideas
- about how you may use each of these, let's see where they can be
- found.
-
- DIRECTORIES AND THEIR FILES:
- The organization of the Companion Disk parallels that of the book. The
- C source code and header files from each chapter are stored in a
- subdirectory named for the chapter--ch2, ch3, ..., ch21. (There are no
- directories for Chapters 1 and 9 because they contain no examples, nor
- for Chapter 11 because all of its examples can be found in Chapter
- 10.)
- Each complete order-entry function is stored in its own source file,
- with the same name as the function. For example, the function prompt()
- from Chapter 10 is found in subdirectory \ch10 in the file prompt.c.
- Some utility main() functions are also stored in ".c" files named for
- their intended uses. For instance, the line-numbering utility program
- from chapter 8 is in directory \ch8 in the file named listing.c, and
- the source-code reindenter is in \ch15\rein.c.
- Other functions and code segments are stored in files named for the
- page where they appear in the book. When there is more than one
- example on a page, the file name includes a letter indicating the
- code's position on that page. For instance, the single example on page
- 9 is stored in the file \ch2\page9.c, but the two segments listed on
- page 22 of Chapter 2 are stored in the directory \ch2 in the files
- page22a.c and page22b.c.
-
- EXPERIMENTING WITH EXAMPLE PROGRAMS:
-
- ***If you haven't already done so, be sure to make a backup copy of
- the Companion Disk and store it in a safe place before you begin
- working with the code.***
-
- You will learn C more quickly if you experiment with the new concepts
- presented in the examples. For instance, let's suppose that you are
- reading the first program on page 22 of "Variations in C" and are
- curious about the effects of modifying it to input a short int and a
- double, rather than a long int and a double, as it does now. With the
- Companion Disk in drive A and your own C source data disk in drive B,
- you can copy the program like this:
-
- COPY A:\CH2\PAGE22A.C B:
-
- (Although they are not needed in this case, some examples do require
- that the header files from Chapter 10 be #included, so copy them as
- well, using the syntax COPY A:\CH10\*.H B:)
-
-
-
- Now you can edit the program and change some of the declarations,
- comments, and format specifiers, so that the program reads:
-
- /* This program will input and output short and double data. */
-
- #include <stdio.h> /* We'll learn about this later. */
-
- main()
- {
- short shrt; /* Declare variables and their types. */
- double dbl;
-
- printf("Enter short int and double: "); /* Prompt for numbers. */
- scanf("%hd %F", &shrt, &dbl); /* Input numbers. */
-
- printf("You entered %d %f.\n", shrt, dbl); /* Display results. */
- }
-
- With these changes made, the program is ready for you to compile,
- link, and execute.
- Not all files on this disk are complete programs, however. Consider
- the second code segment on page 50 in Chapter 4 (\CH4\PAGE50B.C) that
- strips leading spaces from a string named "text". It lacks definition
- of a main() function--declarations, input of text to process, and
- output of results. But when you insert the code from page 50 into the
- framework shown below, it is ready for you to compile:
-
- /* Framework for code on page 50 of Chapter 4 (\CH4\PAGE50B.C). */
- main()
- {
- short from_pos, to_pos, last_space;
- char text[81];
-
- printf("\nEnter text: ");
- gets(text);
-
-
- /*** Insert segment from file \CH4\PAGE50B.C here. ***/
-
-
- printf("\ntext is now %s, len = %d\n", text, strlen(text));
- }
-
- BUILDING AND USING THE PROJECT UTILITY LIBRARY:
- The general nature of the project utility functions will make them
- useful tools in a variety of your own applications, if you take the
- time to make them readily accessible. Here's how.
- Use the MS-DOS LIB command to build a library holding these utility
- functions, AFTER you have compiled each of them to object form. First,
- request the interactive form of the LIB command by typing LIB. Then
- choose a name for your new library and enter it in response to the
- "Library name:" prompt. LIB will create the file for you. Finally, add
- your object files to the library file at the "Operations:" prompt, by
- typing a plus sign and file name (+ MATCH) for each file you want to
- include. From then on, you may call these utility functions from
- within your programs by specifying the name of your project utility
- library to the LINK command, along with the names of your own
- functions and the other libraries you use.
-
- BUILDING THE ORDER-ENTRY PROGRAM:
- The Companion Disk contains the complete source code for the order-
- entry application program, as listed in Chapter 10. (Chapters 11
- through 13 describe these general-purpose and application-specific
- functions in detail.) You may use the order-entry program directly,
- applying it to taking orders for your own business, or you may choose
- to extend it first with new subsystems or additional capabilities.
-
- To turn the existing source code into a working order-entry program,
- just compile and link all the functions from Chapter 10 (except those
- in the files stubs.c and page123.c), plus those listed in the table
- below (the working versions of the functions in stubs.c):
-
- Stub Function File with Working Function
- ============= ==========================
- inv_find() \ch19\inv_find.c
- pw_find() \ch17\pw_find.c
- order_num() \ch17\ordernum.c
- logentry() \ch17\logentry.c
-
- If you have already built the project utility library, then you won't
- need to compile the project utility functions again now. Instead, just
- tell the linker to find them in the library you created earlier.
- To adapt the order-entry program to a completely different
- application, replace the main() function in ordentry.c and the middle-
- level functions in ordbuild.c with code that prompts for your own kind
- of data, rather than order data. Remember to replace the contents of
- the ordentry.h file with descriptions of the new data. The overall
- program structure may require little, if any, modification to handle a
- variety of applications.
-
- QUESTIONS ABOUT THE DISK:
- Should you have any problems with your disk, please write to:
-
- Microsoft Press
- Attn: Sales Division
- Box 97200
- 10700 Northup Way
- Bellevue, WA 98009
-
- If you have any questions about the programs or code segments included
- on the Companion Disk, please write to:
-
- Steve Schustack
- 968 Emerald Street, Suite A-116
- San Diego, CA 92109
-